1 /*
2  * Copyright (C) 2010 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 /**
18  * @addtogroup Asset
19  * @{
20  */
21 
22 /**
23  * @file asset_manager.h
24  */
25 
26 module android.ndk.asset_manager;
27 
28 import core.sys.posix.sys.types;
29 
30 import arsd.jni;
31 import android.ndk;
32 
33 extern (C):
34 nothrow:
35 @nogc:
36 
37 struct AAssetManager;
38 /**
39  * {@link AAssetManager} provides access to an application's raw assets by
40  * creating {@link AAsset} objects.
41  *
42  * AAssetManager is a wrapper to the low-level native implementation
43  * of the java {@link AAssetManager}, a pointer can be obtained using
44  * AAssetManager_fromJava().
45  *
46  * The asset hierarchy may be examined like a filesystem, using
47  * {@link AAssetDir} objects to peruse a single directory.
48  *
49  * A native {@link AAssetManager} pointer may be shared across multiple threads.
50  */
51 
52 struct AAssetDir;
53 /**
54  * {@link AAssetDir} provides access to a chunk of the asset hierarchy as if
55  * it were a single directory. The contents are populated by the
56  * {@link AAssetManager}.
57  *
58  * The list of files will be sorted in ascending order by ASCII value.
59  */
60 
61 struct AAsset;
62 /**
63  * {@link AAsset} provides access to a read-only asset.
64  *
65  * {@link AAsset} objects are NOT thread-safe, and should not be shared across
66  * threads.
67  */
68 
69 /** Available access modes for opening assets with {@link AAssetManager_open} */
70 enum
71 {
72     /** No specific information about how data will be accessed. **/
73     AASSET_MODE_UNKNOWN = 0,
74     /** Read chunks, and seek forward and backward. */
75     AASSET_MODE_RANDOM = 1,
76     /** Read sequentially, with an occasional forward seek. */
77     AASSET_MODE_STREAMING = 2,
78     /** Caller plans to ask for a read-only buffer with all data. */
79     AASSET_MODE_BUFFER = 3
80 }
81 
82 /**
83  * Open the named directory within the asset hierarchy.  The directory can then
84  * be inspected with the AAssetDir functions.  To open the top-level directory,
85  * pass in "" as the dirName.
86  *
87  * The object returned here should be freed by calling AAssetDir_close().
88  */
89 AAssetDir* AAssetManager_openDir (AAssetManager* mgr, const(char)* dirName);
90 
91 /**
92  * Open an asset.
93  *
94  * The object returned here should be freed by calling AAsset_close().
95  */
96 AAsset* AAssetManager_open (AAssetManager* mgr, const(char)* filename, int mode);
97 
98 /**
99  * Iterate over the files in an asset directory.  A NULL string is returned
100  * when all the file names have been returned.
101  *
102  * The returned file name is suitable for passing to AAssetManager_open().
103  *
104  * The string returned here is owned by the AssetDir implementation and is not
105  * guaranteed to remain valid if any other calls are made on this AAssetDir
106  * instance.
107  */
108 const(char)* AAssetDir_getNextFileName (AAssetDir* assetDir);
109 
110 /**
111  * Reset the iteration state of AAssetDir_getNextFileName() to the beginning.
112  */
113 void AAssetDir_rewind (AAssetDir* assetDir);
114 
115 /**
116  * Close an opened AAssetDir, freeing any related resources.
117  */
118 void AAssetDir_close (AAssetDir* assetDir);
119 
120 /**
121  * Attempt to read 'count' bytes of data from the current offset.
122  *
123  * Returns the number of bytes read, zero on EOF, or < 0 on error.
124  */
125 int AAsset_read (AAsset* asset, void* buf, size_t count);
126 
127 /**
128  * Seek to the specified offset within the asset data.  'whence' uses the
129  * same constants as lseek()/fseek().
130  *
131  * Returns the new position on success, or (off_t) -1 on error.
132  */
133 off_t AAsset_seek (AAsset* asset, off_t offset, int whence);
134 
135 /**
136  * Seek to the specified offset within the asset data.  'whence' uses the
137  * same constants as lseek()/fseek().
138  *
139  * Uses 64-bit data type for large files as opposed to the 32-bit type used
140  * by AAsset_seek.
141  *
142  * Returns the new position on success, or (off64_t) -1 on error.
143  */
144 off64_t AAsset_seek64 (AAsset* asset, off64_t offset, int whence);
145 
146 /**
147  * Close the asset, freeing all associated resources.
148  */
149 void AAsset_close (AAsset* asset);
150 
151 /**
152  * Get a pointer to a buffer holding the entire contents of the assset.
153  *
154  * Returns NULL on failure.
155  */
156 const(void)* AAsset_getBuffer (AAsset* asset);
157 
158 /**
159  * Report the total size of the asset data.
160  */
161 off_t AAsset_getLength (AAsset* asset);
162 
163 /**
164  * Report the total size of the asset data. Reports the size using a 64-bit
165  * number insted of 32-bit as AAsset_getLength.
166  */
167 off64_t AAsset_getLength64 (AAsset* asset);
168 
169 /**
170  * Report the total amount of asset data that can be read from the current position.
171  */
172 off_t AAsset_getRemainingLength (AAsset* asset);
173 
174 /**
175  * Report the total amount of asset data that can be read from the current position.
176  *
177  * Uses a 64-bit number instead of a 32-bit number as AAsset_getRemainingLength does.
178  */
179 off64_t AAsset_getRemainingLength64 (AAsset* asset);
180 
181 /**
182  * Open a new file descriptor that can be used to read the asset data. If the
183  * start or length cannot be represented by a 32-bit number, it will be
184  * truncated. If the file is large, use AAsset_openFileDescriptor64 instead.
185  *
186  * Returns < 0 if direct fd access is not possible (for example, if the asset is
187  * compressed).
188  */
189 int AAsset_openFileDescriptor (AAsset* asset, off_t* outStart, off_t* outLength);
190 
191 /**
192  * Open a new file descriptor that can be used to read the asset data.
193  *
194  * Uses a 64-bit number for the offset and length instead of 32-bit instead of
195  * as AAsset_openFileDescriptor does.
196  *
197  * Returns < 0 if direct fd access is not possible (for example, if the asset is
198  * compressed).
199  */
200 int AAsset_openFileDescriptor64 (AAsset* asset, off64_t* outStart, off64_t* outLength);
201 
202 /**
203  * Returns whether this asset's internal buffer is allocated in ordinary RAM (i.e. not
204  * mmapped).
205  */
206 int AAsset_isAllocated (AAsset* asset);
207 
208 // ANDROID_ASSET_MANAGER_H
209 
210 /** @} */